package com.cainiao.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Message  返回值封装类
 *
 */
public class Message<T> implements Serializable {

    private static final long serialVersionUID = -6260655681975239861L;
    private String            r;                                       // 状态码
    private String            msg;                                     // 返回信息
    private long              total            = 0;                    // 总记录数
    private List<T>           data             = new ArrayList<T>();   // 多条数据列表
    private Object            item;                                    // 单条数据

    public Message(){

    }

    /**
     * 快捷设置Message对象
     * 
     * @param r
     * @param msg
     * @param total
     * @return
     */
    public Message<T> setMessage(Integer r, String msg, Integer total) {
        if (r != null) {
            this.setR(String.valueOf(r));
        }
        if (msg != null) {
            this.setMsg(msg);
        }
        if (total != null) {
            this.setTotal((long) total);
        }
        return this;
    }

    /**
     * 向list添加元素
     * 
     * @return
     */
    public void addData(T element) {
        if (this.data == null) {
            this.data = new ArrayList<T>();
        }
        this.data.add(element);
    }
    public String getR() {
        return r;
    }

    public void setR(String r) {
        this.r = r;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public List<T> getData() {
        return data;
    }

    public Object getItem() {
        return item;
    }

    public void setItem(Object item) {
        this.item = item;
    }

}
